<?php


/*-----------用户注册验证器-------------*/
namespace app\common\validate;
use think\Validate;

class User extends Validate
{

    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
        'name|姓名' => [
            'require'   => 'require',
            'min'       => 3,
            'max'       => 20,
            'alphaNum',
            'checkName' => "",
        ],
        'email|邮箱'    => [
            'require'   => 'require',
            'email'     => 'email',
            'min'       => 6,
            'max'       => 50,
        ],
        'password|密码' => [
            'require'   => 'require', //必须的
            'min'       => 5,         //最小3位
            'max'       => 30,        //最大30位
            'regex'     => '/^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/',
        ],
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [
        'name.require'          =>  "昵称",
        'name.checkName'        =>  "昵称不可用",
        'name.min'              =>  "昵称长度太低",
        'name.max'              =>  "昵称长度太长",
        'email.require'         =>  "邮箱必须？",
        'email'                 =>  "邮箱格式错误",
        'email.min'             =>  "邮箱长度太低",
        'email.max'             =>  "邮箱长度太高",
        'password.require'      =>  "密码----",
        'password.min'          =>  "密码太短",
        'password.max'          =>  "密码太长",
        'password.regex'        =>  "密码不符合规则",
    ];

    // 自定义验证规则
    protected function checkName($value){
        $names = array(
            "admin",
        );
        if(in_array($value,$names,true)){
            return false;
        }
        return true;
    }

}
